package com.wss.day06.time;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.Scanner;

/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/4/26
 */
public class Test02 {
    public static void main(String[] args) {
        LocalDate now = LocalDate.now();
        LocalDate birthday = LocalDate.of(2004, 3, 18);
        long days = Math.abs(now.until(birthday, ChronoUnit.DAYS));
        System.out.println("出生日期至今的天数 = "+days);


        LocalDateTime plusDay = LocalDateTime.now().plusDays(3);
        System.out.println("plusDay = "+plusDay);
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        String str = pattern.format(plusDay);
        System.out.println("plusDay = "+str);


        LocalDate date = LocalDate.of(2024, 5, 10);
        System.out.println("过期时间："+date.plusDays(180));

        LocalDate thirdDayOfLastMonth = LocalDate.now()
                .minusMonths(1)
                .withDayOfMonth(3);
        System.out.println("上个月第三天是：" + thirdDayOfLastMonth.getDayOfWeek());

        LocalDate nextMonth = LocalDate.now().plusMonths(1);
        LocalDate lastDayOfNextMonth = nextMonth
                .with(TemporalAdjusters.lastDayOfMonth());
        LocalDate thirdLastDay = lastDayOfNextMonth.minusDays(2);
        System.out.println("下个月倒数第3天是：" + thirdLastDay);

        int dayOfYear = LocalDate.now().getDayOfYear();
        System.out.println("今天是今年的第" + dayOfYear + "天");

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入年份：");
        int year = scanner.nextInt();
        int febDays = YearMonth.of(year, 2).lengthOfMonth();
        System.out.println(year + "年2月份有" + febDays + "天");
        scanner.close();


    }
}
